<?php

namespace App\Listeners;

use Illuminate\Contracts\Queue\ShouldQueue;
use App;
use DB;
use Laravel\Passport\Events\AccessTokenCreated;

class RevokeOldTokens implements ShouldQueue
{

    public $queue = 'passport';

    /**
     * Create the event listener.
     */
    public function __construct()
    {
    }

    /**
     * Handle the event.
     *
     * @param  AccessTokenCreated $event
     * @return void
     */
    public function handle(AccessTokenCreated $event)
    {
        if (App::environment() == 'production')

            DB::table('oauth_access_tokens')
                ->where('id', '<>', $event->tokenId)
                ->where('user_id', $event->userId)
                ->where('client_id', $event->clientId)
                ->delete();
    }
}
